package com.g8.pethospitallearnbackend.mapper;

import com.g8.pethospitallearnbackend.entity.Case;
import com.g8.pethospitallearnbackend.entity.CaseExample;
import com.g8.pethospitallearnbackend.entity.CaseIntro;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface CaseMapper {
    @SelectProvider(type=CaseSqlProvider.class, method="countByExample")
    long countByExample(CaseExample example);

    @DeleteProvider(type=CaseSqlProvider.class, method="deleteByExample")
    int deleteByExample(CaseExample example);

    @Delete({
        "delete from `case`",
        "where case_id = #{caseId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String caseId);

    @Insert({
        "insert into `case` (case_id, case_time, ",
        "case_diseases, pet_info, ",
        "case_symptom, case_check, ",
        "case_diagnosis, case_medicine, ",
        "case_treat, case_symptom_pic, ",
        "case_symptom_video, case_check_pic, ",
        "case_check_video, case_diagnosis_pic, ",
        "case_diagnosis_video, case_treat_pic, ",
        "case_treat_video,default1,default2,default3)",
        "values (#{caseId,jdbcType=VARCHAR}, #{caseTime,jdbcType=TIME}, ",
        "#{caseDiseases,jdbcType=LONGVARCHAR}, #{petInfo,jdbcType=LONGVARCHAR}, ",
        "#{caseSymptom,jdbcType=LONGVARCHAR}, #{caseCheck,jdbcType=LONGVARCHAR}, ",
        "#{caseDiagnosis,jdbcType=LONGVARCHAR}, #{caseMedicine,jdbcType=LONGVARCHAR}, ",
        "#{caseTreat,jdbcType=LONGVARCHAR}, #{caseSymptomPic,jdbcType=LONGVARCHAR}, ",
        "#{caseSymptomVideo,jdbcType=LONGVARCHAR}, #{caseCheckPic,jdbcType=LONGVARCHAR}, ",
        "#{caseCheckVideo,jdbcType=LONGVARCHAR}, #{caseDiagnosisPic,jdbcType=LONGVARCHAR}, ",
        "#{caseDiagnosisVideo,jdbcType=LONGVARCHAR}, #{caseTreatPic,jdbcType=LONGVARCHAR}, ",
        "#{caseTreatVideo,jdbcType=LONGVARCHAR},#{default1,jdbcType=VARCHAR},#{default2,jdbcType=VARCHAR},#{default3,jdbcType=VARCHAR})"
    })
    int insert(Case record);

    @InsertProvider(type=CaseSqlProvider.class, method="insertSelective")
    int insertSelective(Case record);

    @SelectProvider(type=CaseSqlProvider.class, method="selectByExampleWithBLOBs")
    @Results({
        @Result(column="case_id", property="caseId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="case_time", property="caseTime", jdbcType=JdbcType.TIME),
        @Result(column="case_diseases", property="caseDiseases", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="pet_info", property="petInfo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom", property="caseSymptom", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check", property="caseCheck", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis", property="caseDiagnosis", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_medicine", property="caseMedicine", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat", property="caseTreat", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom_pic", property="caseSymptomPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom_video", property="caseSymptomVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check_pic", property="caseCheckPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check_video", property="caseCheckVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis_pic", property="caseDiagnosisPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis_video", property="caseDiagnosisVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat_pic", property="caseTreatPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat_video", property="caseTreatVideo", jdbcType=JdbcType.LONGVARCHAR)
    })
    List<Case> selectByExampleWithBLOBs(CaseExample example);

    @SelectProvider(type=CaseSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="case_id", property="caseId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="case_time", property="caseTime", jdbcType=JdbcType.TIME)
    })
    List<Case> selectByExample(CaseExample example);

    @Select({
        "select",
        "case_id, case_time, case_diseases, pet_info, case_symptom, case_check, case_diagnosis, ",
        "case_medicine, case_treat, case_symptom_pic, case_symptom_video, case_check_pic, ",
        "case_check_video, case_diagnosis_pic, case_diagnosis_video, case_treat_pic, ",
        "case_treat_video",
        "from case",
        "where case_id = #{caseId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="case_id", property="caseId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="case_time", property="caseTime", jdbcType=JdbcType.TIME),
        @Result(column="case_diseases", property="caseDiseases", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="pet_info", property="petInfo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom", property="caseSymptom", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check", property="caseCheck", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis", property="caseDiagnosis", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_medicine", property="caseMedicine", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat", property="caseTreat", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom_pic", property="caseSymptomPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_symptom_video", property="caseSymptomVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check_pic", property="caseCheckPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_check_video", property="caseCheckVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis_pic", property="caseDiagnosisPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_diagnosis_video", property="caseDiagnosisVideo", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat_pic", property="caseTreatPic", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="case_treat_video", property="caseTreatVideo", jdbcType=JdbcType.LONGVARCHAR)
    })
    Case selectByPrimaryKey(String caseId);

    @UpdateProvider(type=CaseSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Case record, @Param("example") CaseExample example);

    @UpdateProvider(type=CaseSqlProvider.class, method="updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") Case record, @Param("example") CaseExample example);

    @UpdateProvider(type=CaseSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Case record, @Param("example") CaseExample example);

    @UpdateProvider(type=CaseSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Case record);

    @Update({
        "update `case`",
        "set case_time = #{caseTime,jdbcType=TIME},",
          "case_diseases = #{caseDiseases,jdbcType=LONGVARCHAR},",
          "pet_info = #{petInfo,jdbcType=LONGVARCHAR},",
          "case_symptom = #{caseSymptom,jdbcType=LONGVARCHAR},",
          "case_check = #{caseCheck,jdbcType=LONGVARCHAR},",
          "case_diagnosis = #{caseDiagnosis,jdbcType=LONGVARCHAR},",
          "case_medicine = #{caseMedicine,jdbcType=LONGVARCHAR},",
          "case_treat = #{caseTreat,jdbcType=LONGVARCHAR},",
          "case_symptom_pic = #{caseSymptomPic,jdbcType=LONGVARCHAR},",
          "case_symptom_video = #{caseSymptomVideo,jdbcType=LONGVARCHAR},",
          "case_check_pic = #{caseCheckPic,jdbcType=LONGVARCHAR},",
          "case_check_video = #{caseCheckVideo,jdbcType=LONGVARCHAR},",
          "case_diagnosis_pic = #{caseDiagnosisPic,jdbcType=LONGVARCHAR},",
          "case_diagnosis_video = #{caseDiagnosisVideo,jdbcType=LONGVARCHAR},",
          "case_treat_pic = #{caseTreatPic,jdbcType=LONGVARCHAR},",
          "case_treat_video = #{caseTreatVideo,jdbcType=LONGVARCHAR},",
            "default1 = #{default1,jdbcType=VARCHAR},",
            "default2 = #{default2,jdbcType=VARCHAR},",
            "default3 = #{default3,jdbcType=VARCHAR}",
        "where case_id = #{caseId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKeyWithBLOBs(Case record);

    @Update({
        "update case",
        "set case_time = #{caseTime,jdbcType=TIME}",
        "where case_id = #{caseId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Case record);
    @Select("select case_id,case_time,default1 from `case` where" +
            " case_diseases like CONCAT('%', #{diseaseId}, '%')")
    List<CaseIntro> selectIntros(@Param("diseaseId") String diseaseId);

    // !!!!!!!!!!!!case是关键字，记得加反引号！！！！！！！！！！！
    @Select("select * from `case` where case_id=#{caseId};")
    Case selectACaseById(@Param("caseId") String caseId);

    @Select("select * from `case`;")
    List<Case> selectAllCases();

    @Update("alter table case add column #{columnName} varchar(255)")
    void alterAddColumn(@Param("columnName") String enAttr);

    @Select("select case_id from `case`")
    List<String> selectAllCaseIds();

    @Select("select case_medicine from `case`;")
    List<String> selectAllMedicine();

    @Select("select case_check from `case`;")
    List<String> selectAllLab();
}